import { Sorter } from './Sorter';

//管理数值数组的逻辑
export class NumberColloection extends Sorter {
  constructor(public data: number[]) {
    super();
  }

  //get关键字可以改变访问长度的方式this.length() -> this.length
  get length(): number {
    return this.data.length;
  }

  //对比数组里元素前一项是否大于后一项
  compare(leftIndex: number, rightIndex: number): boolean {
    return this.data[leftIndex] > this.data[rightIndex];
  }

  //交换位置
  swap(leftIndex: number, rightIndex: number): void {
    const leftHand = this.data[leftIndex];
    this.data[leftIndex] = this.data[rightIndex];
    this.data[rightIndex] = leftHand;
  }
}
